#include "Algorithm_Filter.h"
/**
  ******************************************************************************
  * @file    Algorithm_Filter.c
  * @author  zipeng
  * @version V1.0
  * @date		 2022/2/17
  * @brief   The file of filter.
	* @copyright (c) 2017-2025 JZI. All rights reserved.
  ******************************************************************************
  */

RAW_DATA BatData = {.flag = 0,\
					.index = 0,\
					.ftemp = 0,\
					.Move_Solid_Filter = &Move_Solid_Filter\
};

float Move_Solid_Filter(float raw)
{
	BatData.cur[BatData.index]  = raw;
	BatData.ftemp +=  BatData.cur[BatData.index];
	BatData.ftemp -=  BatData.cur[FIFOLEN-1-BatData.index];
	
	BatData.index++;
	if(BatData.index>=FIFOLEN){
		BatData.flag = 1;
		BatData.index = 0;
	}
	if(BatData.flag!=1){
		return raw;
	}
	else{
		return BatData.ftemp/HALFLEN;
	}
}

